#include <Windows.h>
#include <tchar.h>

VOID CALLBACK WaitProc(PTP_CALLBACK_INSTANCE Instance, PVOID Parameter, PTP_WAIT Wait, TP_WAIT_RESULT WaitResult)
{	
	Sleep(500);
	_tprintf(_T("wait call back! 0x%0x\n"), GetCurrentThreadId());
}

VOID ThreadPoolForWait()
{
	HANDLE hEvent	= CreateEvent(NULL, FALSE, FALSE, NULL);
	PTP_WAIT Wait	= CreateThreadpoolWait((PTP_WAIT_CALLBACK)WaitProc, NULL, NULL);
	if(NULL != Wait)
	{
		for (int ii = 0; ii < 5; ii ++) 
		{
			SetThreadpoolWait(Wait, hEvent, NULL);
			SetEvent(hEvent);			
			WaitForThreadpoolWaitCallbacks(Wait, FALSE);
		}
		SetThreadpoolWait(Wait, NULL, NULL);
		CloseThreadpoolWait(Wait);
	} 

	CloseHandle(hEvent);
	
	return;
}

void main()
{
	ThreadPoolForWait();

	return;
}